﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Context;
using Entities;
namespace WCF_ListenMusic.Services.Module_Song.Public
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "UserService" in code, svc and config file together.
    public class UserService : IUserService
    {
        Context.Connect_DBDataContext context = new Context.Connect_DBDataContext();
        public bool register(Member member)
        {
            try
            {
                context.Members.InsertOnSubmit(member);
                context.SubmitChanges();
                return true;
            }
            catch (Exception e) { return false; throw new FaultException(e.Message); }
        }


        public List<ViewSearch> memberSearch(string keyword)
        {
            try
            {
                var q = from a in context.ViewSearches
                        join b in context.search_ViewSearch(keyword) on a.SongID equals b.KEY
                        select a;
                return q.ToList();
            }
            catch (Exception e) { return null; throw new FaultException(e.Message); }
        }


    
       
        //#region IUserService Members


        //public Member checkLogin(string email, string password)
        //{
        //    try
        //    {
        //        if (email == null || password == null)
        //        {
        //            throw new FaultException("Email Và Mật Khẩu Không Được Để Trống");
        //        }
        //        else
        //        {
        //            try
        //            {
        //                var q = from m in context.Members
        //                        where m.Email.Equals(email) && m.mPassword.Equals(password)
        //                        select m;
        //                return q.Single();
        //            }
        //            catch (InvalidOperationException ix)
        //            {
        //                throw new FaultException("Email Hoặc Password Sai");
        //            }

        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new FaultException(ex.Message);
        //    }
        //}

        //#endregion


        //public Member checkEmail(string email)
        //{
        //    try
        //    {
        //        var q = from a in context.Members
        //                where a.Email.Equals(email)
        //                select a;
        //        return q.Single();
        //    }
        //    catch (Exception e) { throw new FaultException(e.Message); }
        //}


    }
}